package com.mmall.util;


import org.apache.commons.lang3.StringUtils;

//脱敏
public class HideStr {

    static public String doHide(String src, int begin, int length) {
        if (StringUtils.isEmpty(src)) {
            return "";
        }
        src = src.trim();
        String pre = src.substring(0, begin);
        String sub = src.substring((begin + length) > src.length() ? src.length() : (begin + length));
        int hideCount = src.length() - pre.length() - sub.length();
        StringBuilder buff = new StringBuilder();
        buff.append(pre);
        for (int i = 0; i < hideCount; i++) {
            buff.append("*");
        }
        buff.append(sub);
        return buff.toString();
    }

    public static void main(String[] args) {
        System.out.println(doHide(" bcde", 1, 3));
    }
}
